package core

import (
	"os"
	"text/template"
)

var GetServiceGenerator = new(ServiceGenerator)

type ServiceGenerator struct{}

func (c *ServiceGenerator) GenerateService(tableName string, StructName string, structName string) {

	param := Param{
		TableName:    tableName,
		StructName:   StructName,
		VariableName: structName,
	}
	tmplFile := "templates/service.tmpl"
	outputFile := "code/service/" + StructName + "Service.go"
	//创建模板
	tmpl, err := template.ParseFiles(tmplFile)
	if err != nil {
		panic(err)
	}

	// 创建输出文件
	out, err := os.Create(outputFile)
	if err != nil {
		panic(err)
	}
	defer out.Close()

	// 执行模板，将结果写入输出文件
	err = tmpl.Execute(out, param)
	if err != nil {
		panic(err)
	}

}
